package com.kbot.bot.gui.loader;

import com.kbot.bot.debug.Debug;

import java.applet.Applet;
import java.net.URLClassLoader;
import java.net.URL;
import java.net.MalformedURLException;

/**
 * Created by IntelliJ IDEA.
 * User: Jan Ove
 * Date: 29.jan.2009
 * Time: 17:28:08
 * To change this template use File | Settings | File Templates.
 */
public class AppletInstance {
    public static Applet addNewBot(String world) {
        try {
            URLClassLoader theClassLoader = new URLClassLoader(new URL[]{new URL("file:client/runescape.jar")});
            Debug.write("JAR loaded: "+theClassLoader.getURLs()[0].toString());
            Applet theApplet = (Applet) theClassLoader.loadClass("client").newInstance();
            theApplet.setStub(new StubGenerator(world));
            theApplet.init();
            theApplet.start();
            Debug.write("Loaded applet.");
            return theApplet;
        } catch (MalformedURLException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        } catch (ClassNotFoundException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        } catch (IllegalAccessException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        } catch (InstantiationException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
        return null;
   }
}
